package com.ler.yrmall.product.controller;

import com.ler.yrmall.basic.Result;
import com.ler.yrmall.product.entity.SpuAttrValueEntity;
import com.ler.yrmall.product.service.SpuAttrValueService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * spu
 * @author Leron
 */
@RestController
@RequestMapping("/productAttrValue")
public class SpuAttrValueController {

    @Resource
    private SpuAttrValueService productAttrValueService;


    @RequestMapping("/listBySpuId/{spuId}")
    public Result<?> baseAttrForSpu(@PathVariable Long spuId) {
        return Result.ok(productAttrValueService.listBySpuId(spuId));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody SpuAttrValueEntity productAttrValue) {
        productAttrValueService.save(productAttrValue);
        return Result.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public Result<?> update(@RequestBody SpuAttrValueEntity productAttrValue) {
        productAttrValueService.updateById(productAttrValue);
        return Result.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] ids) {
        productAttrValueService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
